const path = require("path");
const json = require("@rollup/plugin-json");
const { babel } = require("@rollup/plugin-babel");
const { SourceMap } = require("module");

const resolveFile = function (filePath) {
  return path.join(__dirname, filePath);
};

const plugins = [
  json({
    compact: true, // 压缩json文件，减少打包体积
  }),
  babel({
    extensions: [".js", ".jsx", ".ts", ".tsx"], // 指定需要转换的文件类型
    babelHelpers: "bundled", // 使用bundled模式，减少打包体积
    presets: [
      // 支持用法的浏览器环境
      [
        "@babel/env",
        {
          targets: {
            browsers: [">1%", "last 2 versions", "not ie <= 8"],
          },
        },
      ],
    ],
  }),
];

module.exports = [
  {
    plugins,
    input: resolveFile("../src/webEyeSDK.js"),
    output: {
      file: resolveFile("../dist/monitor.js"),
      format: "iife", // 打包成iife格式
      name: "monitor",
      sourceMap: true, // 开启sourceMap
    },
  },
  {
    plugins,
    input: resolveFile("../src/webEyeSDK.js"),
    output: {
      file: resolveFile("../dist/monitor.esm.js"),
      format: "esm", // 打包成iife格式
      name: "monitor",
      sourceMap: true, // 开启sourceMap
    },
  },
  {
    plugins,
    input: resolveFile("../src/webEyeSDK.js"),
    output: {
      file: resolveFile("../dist/monitor.cjs.js"),
      format: "cjs", // 打包成iife格式
      name: "monitor",
      sourceMap: true, // 开启sourceMap
    },
  },
];
